<?php
/**
 * 根对象
 *
 * @package util.core
 * @version $Id: IObject.php 312 2008-04-23 16:29:38Z iwind $
 * @since 0.1
 */
class IObject {
	private $refId;
	
	/**
	 * 取得引用标识ID
	 *
	 * @return string
	 * @since 0.1
	 */
	public function refId() {
		if ($this->refId == null) {
			$this->refId = str_replace(".", "_",  uniqid(__CLASS__ . "_", true));
		}
		return $this->refId;
	}
	
	/**
	 * 打印值
	 *
	 * @param boolean $return 是否返回，为true时不打印
	 * @param boolean $format 是否格式化
	 * @return string|null
	 * @since 0.1
	 */
	public function dump($return = false, $format = true) {
		$vars = get_object_vars($this);
		foreach ($vars as $key=>$var) {
			if (is_object($var)) {
				$var = get_object_vars($var);
			}
			if (is_array($var)) {
				foreach ($var as $k=>$v) {
					if (!is_scalar($v) && !is_null($v)) {
						if (is_object($v)) {
							$var[$k] = get_class($v) . " Object";
						}
						else {
							$var[$k] = ucfirst(gettype($v));
						}
					}
				}
				$vars[$key] = $var;
			}
		}
		$print = print_r($vars, true);
		if ($format) {
			$print = str_replace(" ", "&nbsp;", $print);
			$print = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $print);
			$print = preg_replace("/\r?\n/", "<br/>\n", $print);
		}
		if ($return) {
			return $print;
		}
		else {
			echo $print;
			return null;
		}
	}
}

?>